package 克隆;

class Money implements Cloneable{
    public double tmp=19.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable {
    public int age;
    public String name;
    public double score;
    public Money money=new Money();

    public Student(int age, String name, double score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student tmp=(Student) super.clone();
        tmp.money=(Money) this.money.clone();
        return tmp;
    }

}
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {
        Student stu1=new Student(12,"wzj",78.5);
        Student stu2=(Student) (stu1.clone());
        stu2.money.tmp=99.9;
        System.out.println(stu2.money.tmp);
        System.out.println(stu1.money.tmp);
    }
}
